package com.xuhf.consumerPullPush;

import com.xuhf.config.Config;
import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer;
import org.apache.rocketmq.client.consumer.PullResult;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.common.message.MessageQueue;

public class PullConsumer {

    public static void main(String[] args) throws Exception {
        //创建一个拉取消息的消费者对象
        DefaultMQPullConsumer consumer = new DefaultMQPullConsumer(Config.CONSUMER_GROUP);
        //设置名字地址
        consumer.setNamesrvAddr(Config.NAMESRV_ADDR);
        //启动消费者
        consumer.start();
        PullResult pullResult = consumer.pull(new MessageQueue("03-pull-push", "LAPTOP-IBO28OT3", 0), "*", 0, 1);
        for (MessageExt messageExt : pullResult.getMsgFoundList()) {
            System.out.println("消费线程:" + Thread.currentThread().getName() + ",消息ID:" + messageExt.getMsgId() + "," +
                    "消息内容:" + new String(messageExt.getBody()));
        }
        consumer.shutdown();
    }
}
